/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmPrincipal.java
 *
 * Created on 18/06/2011, 01:25:19
 */
package com.pedagio.view;

import com.pedagio.dominio.EstacaoPedagio;
import com.pedagio.negocio.EstacaoPedagioService;
import com.pedagio.util.Controle;
import com.pedagio.util.DataBaseServer;
import com.pedagio.util.JanelasUtil;

/**
 *
 * @author pedroo
 */
public class FrmPrincipal extends javax.swing.JFrame {
    public static final Long ID_ESTACAO_CORRENTE = 1L;

    private EstacaoPedagioService estacaoPedagioService = Controle.getEstacaoPedagioService();

    /** Creates new form FrmPrincipal */
    public FrmPrincipal() {
        initComponents();
    }

    public void inicializarEstacao() {
        EstacaoPedagio estacao = estacaoPedagioService.find(ID_ESTACAO_CORRENTE);
        if(estacao == null) {
            estacao = new EstacaoPedagio();
            estacao.setId(ID_ESTACAO_CORRENTE);
            estacao.setDescricao("Nome da Estação");
            estacao.setLocalizacao("Endereco");
            estacao.setValorPedagio(10.32);
            estacaoPedagioService.persist(estacao);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnVeiculo = new javax.swing.JButton();
        btnSmartCard = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        ComputadorBordo = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(242, 247, 247));

        btnVeiculo.setText("Cadastro de Usuario");
        btnVeiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVeiculoActionPerformed(evt);
            }
        });

        btnSmartCard.setText("Agendamento de Consulta");
        btnSmartCard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSmartCardActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel1.setText("Sistema de Agendamento");

        ComputadorBordo.setText("Agendamento de Exame");
        ComputadorBordo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComputadorBordoActionPerformed(evt);
            }
        });

        jButton1.setText("Sair do Sistema");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ComputadorBordo, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE)
                .addGap(23, 23, 23))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(200, 200, 200)
                .addComponent(jButton1)
                .addContainerGap(186, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(btnSmartCard, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnVeiculo, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)
                .addGap(20, 20, 20))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(53, 53, 53)
                .addComponent(btnSmartCard, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(btnVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addComponent(ComputadorBordo, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVeiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVeiculoActionPerformed
        FrmUsuario frmVeiculo = new FrmUsuario(this, true);
        JanelasUtil.centerAndShow(frmVeiculo);
        
    }//GEN-LAST:event_btnVeiculoActionPerformed

    private void btnSmartCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSmartCardActionPerformed
        FrmCadastroConsulta consulta = new FrmCadastroConsulta(this, true);
        JanelasUtil.centerAndShow(consulta);

    }//GEN-LAST:event_btnSmartCardActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        DataBaseServer.stop();
    }//GEN-LAST:event_formWindowClosed

    private void ComputadorBordoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComputadorBordoActionPerformed
        FrmCadastroExame cadastroExame = new FrmCadastroExame(this, true);
        JanelasUtil.centerAndShow(cadastroExame);
    }//GEN-LAST:event_ComputadorBordoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        System.exit(1);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        
        DataBaseServer.start();
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                
                FrmPrincipal principal = new FrmPrincipal();
                JanelasUtil.centerAndShow(principal);
                principal.inicializarEstacao();
                


            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ComputadorBordo;
    private javax.swing.JButton btnSmartCard;
    private javax.swing.JButton btnVeiculo;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
